var t = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Page({
    data: {
        btn_loading: !1,
        btn_disabled: !1,
        btn_loading_text: "提交中..",
        checked: !1,
        register_type: [],
        register_type_list: [ 1, 2 ],
        showPicker: !1,
        agree: !1,
        columns: [ "居民身份证", "港澳居民来往内地通行证", "台胞证" ],
        identity_card_front: [],
        identity_card_backend: [],
        show_agreement: !1,
        showSex: !1,
        showBirth: !1,
        info: {
            name: "",
            mobile: "",
            identity_card_no: "",
            identity_card_type: "",
            identity_card_front: "",
            identity_card_backend: "",
            gender: "",
            birthday: ""
        },
        sexList: [ "男", "女" ],
        minDate: new Date(1900, 0, 1).getTime(),
        maxDate: new Date(2030, 12, 31).getTime(),
        currentDate: new Date().getTime(),
        redirect: !1,
        desc: "",
        register_type_Id: null
    },
    onLoad: function(t) {
        t.register_type_Id && (this.data.register_type.push(t.register_type_Id), this.setData({
            register_type: this.data.register_type,
            register_type_Id: t.register_type_Id
        })), this.getData(), this.checkAllHandle();
    },
    choose: function(t) {
        this.setData({
            register_type: t.detail
        }), 2 == this.data.register_type.length ? this.setData({
            checked: !0
        }) : this.setData({
            checked: !1
        });
    },
    onChange: function() {
        if (this.setData({
            checked: !this.data.checked
        }), this.data.checked) {
            var t = this.selectComponent(".checkboxGroup-0"), e = this.selectComponent(".checkboxGroup-1");
            if (1 == this.data.register_type.length) {
                var a = this.data.register_type[0] - 1;
                this.selectComponent(".checkboxGroup-".concat(a)).toggle();
            } else t.toggle(), e.toggle();
            this.setData({
                register_type: [ "1", "2" ],
                checked: !0
            });
        } else this.setData({
            register_type: [],
            checked: !1
        });
    },
    checkAllHandle: function() {},
    getData: function() {
        var t = this;
        e._postNetWork({
            url: e.getNetAddresss("plugin.worker-withdraw.frontend.register.page"),
            data: {
                register_type: this.data.register_type_Id
            },
            success: function(a) {
                if (1 == a.data.result) {
                    var i = a.data.data.register_data;
                    t.setData({
                        desc: a.data.data.desc
                    }), i && (t.setData({
                        "info.name": i.name,
                        "info.mobile": i.mobile,
                        "info.identity_card_no": i.identity_card_no,
                        "info.identity_card_front": i.identity_card_front,
                        "info.identity_card_backend": i.identity_card_backend,
                        "info.birthday": i.birthday
                    }), "1" == i.identity_card_type ? t.setData({
                        "info.identity_card_type": "居民身份证"
                    }) : "2" == i.identity_card_type ? t.setData({
                        "info.identity_card_type": "港澳居民来往内地通行证"
                    }) : t.setData({
                        "info.identity_card_type": "台胞证"
                    }), 0 == a.data.gender ? t.setData({
                        "info.gender": "女"
                    }) : t.setData({
                        "info.gender": "男"
                    }), t.setData({
                        identity_card_backend: [ {
                            url: i.identity_card_backend_url
                        } ],
                        identity_card_front: [ {
                            url: i.identity_card_front_url
                        } ]
                    })), 0 !== a.data.data.register_type.length && t.setData({
                        register_type_list: a.data.data.register_type
                    });
                } else e.tips(a.data.msg);
            }
        });
    },
    onClose: function(e) {
        var a = e.currentTarget.dataset.filed;
        this.setData(t({}, a, !1));
    },
    inputText: function(e) {
        var a = e.currentTarget.dataset.filed, i = e.detail, n = "info.".concat(a);
        this.setData(t({}, n, i));
    },
    agreement: function() {
        this.setData({
            show_agreement: !1
        });
    },
    confirmBirth: function(t) {
        console.log(t);
        var e = new Date(t.detail), a = e.getFullYear(), i = e.getMonth() + 1, n = e.getDate();
        i < 10 && (i = "0".concat(i)), n < 10 && (n = "0".concat(n)), this.setData({
            "info.birthday": "".concat(a, "-").concat(i, "-").concat(n),
            showBirth: !1
        });
    },
    afterRead: function(t) {
        var a = this, i = t.detail.file, n = e.getNetAddresss("upload.uploadPic");
        wx.uploadFile({
            url: n,
            filePath: i.url,
            name: "file",
            formData: null,
            success: function(t) {
                var e = JSON.parse(t.data);
                a.setData({
                    identity_card_backend: [ {
                        url: e.data.img_url
                    } ],
                    "info.identity_card_backend": e.data.img_url
                });
            }
        });
    },
    deletePhotoFront: function() {
        this.setData({
            identity_card_front: []
        });
    },
    deletePhotoBackend: function() {
        this.setData({
            identity_card_backend: []
        });
    },
    onRead_2: function(t) {
        var a = this, i = t.detail.file, n = e.getNetAddresss("upload.uploadPic");
        wx.uploadFile({
            url: n,
            filePath: i.url,
            name: "file",
            formData: null,
            success: function(t) {
                var e = JSON.parse(t.data);
                a.setData({
                    identity_card_front: [ {
                        url: e.data.img_url
                    } ],
                    "info.identity_card_front": e.data.img_url
                });
            }
        });
    },
    closePop: function(e) {
        var a = e.currentTarget.dataset.filed;
        this.setData(t({}, a, !0));
    },
    popup: function(e) {
        var a = e.currentTarget.dataset.filed;
        this.setData(t({}, a, !0));
    },
    onSubmit: function() {
        var t = this;
        if (!this.data.agree) return e.tips("请勾选服务协议");
        if (0 == this.data.register_type.length) return e.tips("请选择注册类型");
        var a = {
            name: this.data.info.name,
            mobile: this.data.info.mobile,
            identity_card_no: this.data.info.identity_card_no,
            identity_card_front: this.data.info.identity_card_front,
            identity_card_backend: this.data.info.identity_card_backend,
            birthday: this.data.info.birthday
        };
        a.register_type = 2 == this.data.register_type.length ? [ -1 ] : this.data.register_type, 
        "男" == this.data.info.gender ? a.gender = 1 : a.gender = 0, "居民身份证" == this.data.info.identity_card_type ? a.identity_card_type = 1 : "港澳居民来往内地通行证" == this.data.info.identity_card_type ? a.identity_card_type = 2 : a.identity_card_type = 3;
        var i = {
            name: "请输入姓名",
            mobile: "请输入手机号",
            identity_card_type: "请选择身份证类型",
            identity_card_no: "请输入证件号",
            gender: "请选择性别",
            birthday: "请选择出生日期",
            identity_card_front: "请上传身份证(人像面)",
            identity_card_backend: "请上传身份证(国徽面)"
        };
        for (var n in i) if ("" == this.data.info[n]) return e.tips(i[n]);
        if (this.data.info.mobile.length < 11) return e.tips("请输入正确的手机号");
        if (!/^[\u4e00-\u9fa5]{2,6}$/.test(this.data.info.name)) return e.tips("请输入真实姓名");
        this.setData({
            btn_loading: !0,
            btn_loading_text: "正在提交...",
            btn_disabled: !0
        }), e._postNetWork({
            url: e.getNetAddresss("plugin.worker-withdraw.frontend.register.index"),
            data: a,
            success: function(t) {
                t.data.result, e.tips(t.data.msg);
            },
            complete: function(e) {
                t.setData({
                    btn_disabled: !1,
                    btn_loading_text: "",
                    btn_loading: !1
                });
            }
        });
    },
    onConfirm: function(t) {
        this.setData({
            "info.identity_card_type": t.detail.value,
            showPicker: !1
        });
    },
    onConfirmGender: function(t) {
        this.setData({
            "info.gender": t.detail.value,
            showSex: !1
        });
    },
    onAgreement: function() {
        this.setData({
            show_agreement: !0
        });
    },
    ready: function() {
        this.setData({
            agree: !this.data.agree
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});